<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>rbjeq</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="randomi.html" title="randomi" />
    <link rel="next" href="readclock.html" title="readclock" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">rbjeq</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="randomi.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="readclock.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="rbjeq"></a>
      <div class="titlepage"></div>
      <a id="IndexRbjeq" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">rbjeq</span>
        </h2>
        <p>rbjeq — 
      Parametric equalizer and filter opcode with 7 filter types, based
      on algorithm by Robert Bristow-Johnson.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp141257392"></a>
        <h2>Description</h2>
        <p>
    	Parametric equalizer and filter opcode with 7 filter types,
    	based on algorithm by Robert Bristow-Johnson.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141258896"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ar <span class="command"><strong>rbjeq</strong></span> asig, kfco, klvl, kQ, kS[, imode]</pre>
      </div>
      <div class="refsect1">
        <a id="idp141261120"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>imode (</em></span>
      optional, defaults to zero) - sum of:

      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>
      			1: skip initialization (should be used in tied, or
      			re-initialized notes only)
      		</p>
            </li>
          </ul>
        </div>
        <p>

      and exactly one of the following values to select filter type:

      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>
      			 0: resonant lowpass filter. kQ controls the resonance: at the
      cutoff frequency (kfco), the amplitude gain is kQ (e.g. 20 dB for
      kQ = 10), and higher kQ values result in a narrower resonance
      peak. If kQ is set to sqrt(0.5) (about 0.7071), there is no
      resonance, and the filter has a response that is very similar to
      that of butterlp. If kQ is less than sqrt(0.5), there is no
      resonance, and the filter has a -6 dB / octave response from about
      kfco * kQ to kfco. Above kfco, there is always a -12 dB / octave
      cutoff.


      		</p>
              <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
                <table border="0" summary="Note: NOTE">
                  <tr>
                    <td rowspan="2" align="center" valign="top" width="25">
                      <img alt="[Note]" src="images/note.png" />
                    </td>
                    <th align="left">NOTE</th>
                  </tr>
                  <tr>
                    <td align="left" valign="top">
                      <p>
      				The rbjeq lowpass filter is basically the same as
      				ar pareq asig, kfco, 0, kQ, 2 but is faster to
      				calculate.
      			</p>
                    </td>
                  </tr>
                </table>
              </div>
              <p>


      		</p>
            </li>
            <li class="listitem">
              <p>
      			2: resonant highpass filter. The parameters are the
      			same as for the lowpass filter, but the equivalent
      			filter is butterhp if kQ is 0.7071, and "ar pareq
      			asig, kfco, 0, kQ, 1" in other cases.
      		</p>
            </li>
            <li class="listitem">
              <p>
      			4: bandpass filter. kQ controls the bandwidth, which
      			is kfco / kQ, and must be always less than sr / 2. The
      			bandwidth is measured between -3 dB points (i.e.
      			amplitude gain = 0.7071), beyond which there is a +/-
      			6 dB / octave slope. This filter type is very similar
      			to ar butterbp asig, kfco, kfco / kQ.
      		</p>
            </li>
            <li class="listitem">
              <p>
      			6: band-reject filter, with the same parameters as the
      			bandpass filter, and a response similar to that of
      			butterbr.
      		</p>
            </li>
            <li class="listitem">
              <p>
      			8: peaking EQ. It has an amplitude gain of 1 (0 dB) at
      			0 Hz and sr / 2, and klvl at the center frequency
      			(kfco). Thus, klvl controls the amount of boost (if it
      			is greater than 1), or cut (if it is less than 1).
      			Setting klvl to 1 results in a flat response.
      			Similarly to the bandpass and band-reject filters, the
      			bandwidth is determined by kfco / kQ (which must be
      			less than sr / 2 again); however, this time it is
      			between sqrt(klvl) points (or, in other words, half
      			the boost or cut in decibels). NOTE: excessively low
      			or high values of klvl should be avoided (especially
      			with 32-bit floats), though the opcode was tested with
      			klvl = 0.01 and klvl = 100. klvl = 0 is always an
      			error, unlike in the case of pareq, which does allow a
      			zero level.
      		</p>
            </li>
            <li class="listitem">
              <p>
      			10: low shelf EQ, controlled by klvl and kS (kQ is
      			ignored by this filter type). There is an amplitude
      			gain of klvl at zero frequency, while the level of
      			high frequencies (around sr / 2) is not changed. At
      			the corner frequency (kfco), the gain is sqrt(klvl)
      			(half the boost or cut in decibels). The kS parameter
      			controls the steepness of the slope of the frequency
      			response (see below).
      		</p>
            </li>
            <li class="listitem">
              <p>
      			12: high shelf EQ. Very similar to the low shelf EQ,
      			but affects the high frequency range.
      		</p>
            </li>
          </ul>
        </div>
        <p>


      The default value for imode is zero (lowpass filter,
      initialization not skipped).

    </p>
      </div>
      <div class="refsect1">
        <a id="idp141275968"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ar</em></span>
      -- the output signal.
    </p>
        <p>
      <span class="emphasis"><em>asig</em></span>
      -- the input signal

      </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note: NOTE">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">NOTE</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
      	If the input contains silent sections, on Intel CPUs a
      	significant slowdown can occur due to denormals. In such
      	cases, it is recommended to process the input signal with
      	"denorm" opcode before filtering it with rbjeq (and actually
      	many other filters).
      </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
    </p>
        <p>
      <span class="emphasis"><em>kfco</em></span>
      -- cutoff, corner, or center frequency, depending on filter type,
      in Hz. It must be greater than zero, and less than sr / 2 (the
      range of about sr * 0.0002 to sr * 0.49 should be safe).
    </p>
        <p>
      <span class="emphasis"><em>klvl</em></span>
      -- level (amount of boost or cut), as amplitude gain (e.g. 1: flat
      response, 4: 12 dB boost, 0.1: 20 dB cut); zero or negative values
      are not allowed. It is recognized by the peaking and shelving EQ
      types (8, 10, 12) only, and is ignored by other filters.
    </p>
        <p>
      <span class="emphasis"><em>kQ</em></span>
      -- resonance (also kfco / bandwidth in many filter types). Not
      used by the shelving EQs (imode = 10 and 12). The exact meaning of
      this parameter depends on the filter type (see above), but it
      should be always greater than zero, and usually (kfco / kQ) less
      than sr / 2.
    </p>
        <p>
      <span class="emphasis"><em>kS</em></span>
      -- shelf slope parameter for shelving filters. Must be greater
      than zero; a higher value means a steeper slope, with resonance if
      kS &gt; 1 (however, a too high kS value may make the filter
      unstable). If kS is set to exactly 1, the shelf slope is as steep
      as possible without a resonance. Note that the effect of kS -
      especially if it is greater than 1 - also depends on klvl, and it
      does not have any well defined unit.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141285712"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the <span class="emphasis"><em>rbjeq</em></span> opcode. It uses the file <a class="ulink" href="examples/rbjeq.csd" target="_top"><em class="citetitle">rbjeq.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp141288000"></a>
          <p class="title">
            <strong>Example 738. An example of the rbjeq opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o rbjeq.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

imode <span class="op">=</span> p4
a1    <span class="opc">vco2</span>    .3, 155.6			<span class="comment">; sawtooth wave</span>
kfco  <span class="opc">expon</span>   8000, p3, 200		<span class="comment">; filter frequency</span>
asig  <span class="opc">rbjeq</span>   a1, kfco, 1, kfco <span class="op">*</span> 0.005, 1, imode
      <span class="opc">outs</span> asig, asig

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1 0  5 0	<span class="comment">;lowpass</span>
<span class="stamnt">i</span> 1 6  5 2	<span class="comment">;highpass</span>
<span class="stamnt">i</span> 1 12 5 4	<span class="comment">;bandpass</span>
<span class="stamnt">i</span> 1 18 5 8	<span class="comment">;equalizer</span>

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141292320"></a>
        <h2>Credits</h2>
        <p>
	  </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Original algorithm by Robert Bristow-Johnson</td>
          </tr>
          <tr>
            <td>
        	Csound orchestra version by Josep M Comajuncosas, Aug 1999
        </td>
          </tr>
          <tr>
            <td>
        	Converted to C (with optimizations and bug fixes) by Istvan
        	Varga, Dec 2002
        </td>
          </tr>
        </table>
        <p>
   </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="randomi.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="readclock.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">randomi </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> readclock</td>
        </tr>
      </table>
    </div>
  </body>
</html>
